﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.ComponentModel;
using System.Web.UI.Design.WebControls;
using System.Web.UI.Design;

namespace SPL.Web.UI
{
    /// <summary>
    /// A designer class for a strongly typed repeater <c>TvtRepeater</c>
    /// </summary>
	public class TvtRepeaterDesigner : System.Web.UI.Design.ControlDesigner
	{
	    /// <summary>
        /// Initializes a new instance of the <see cref="T:TvtRepeaterDesigner"/> class.
        /// </summary>
		public TvtRepeaterDesigner()
		{
		}

        /// <summary>
        /// Initializes the control designer and loads the specified component.
        /// </summary>
        /// <param name="component">The control being designed.</param>
		public override void Initialize(IComponent component)
		{
			if (!(component is TvtRepeater))
			{ 
				throw new ArgumentException("Component is not a TvtRepeater."); 
			} 
			base.Initialize(component); 
			base.SetViewFlags(ViewFlags.TemplateEditing, true); 
		}


		/// <summary>
		/// Generate HTML for the designer
		/// </summary>
		/// <returns>a string of design time HTML</returns>
		public override string GetDesignTimeHtml()
		{

			// Get the instance this designer applies to
			//
			TvtRepeater z = (TvtRepeater)Component;
			z.DataBind();

			return base.GetDesignTimeHtml();

			//return z.RenderAtDesignTime();

			//	ControlCollection c = z.Controls;
			//Totem z = (Totem) Component;
			//Totem z = (Totem) Component;
			//return ("<div style='border: 1px gray dotted; background-color: lightgray'><b>TagStat :</b> zae |  qsdds</div>");

		}
	}

    /// <summary>
    /// A strongly typed repeater control for the <c cref="TvtRepeater"></c> Type.
    /// </summary>
	[Designer(typeof(TvtRepeaterDesigner))]
	[ParseChildren(true)]
	[ToolboxData("<{0}:TvtRepeater runat=\"server\"></{0}:TvtRepeater>")]
	public class TvtRepeater : Control, System.Web.UI.INamingContainer
	{
	    /// <summary>
        /// Initializes a new instance of the <see cref="T:TvtRepeater"/> class.
        /// </summary>
		public TvtRepeater()
		{
		}

		/// <summary>
        /// Gets a <see cref="T:System.Web.UI.ControlCollection"></see> object that represents the child controls for a specified server control in the UI hierarchy.
        /// </summary>
        /// <value></value>
        /// <returns>The collection of child controls for the specified server control.</returns>
		public override ControlCollection Controls
		{
			get
			{
				this.EnsureChildControls();
				return base.Controls;
			}
		}

		private ITemplate m_headerTemplate;
		/// <summary>
        /// Gets or sets the header template.
        /// </summary>
        /// <value>The header template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(TvtItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate HeaderTemplate
		{
			get { return m_headerTemplate; }
			set { m_headerTemplate = value; }
		}

		private ITemplate m_itemTemplate;
		/// <summary>
        /// Gets or sets the item template.
        /// </summary>
        /// <value>The item template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(TvtItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate ItemTemplate
		{
			get { return m_itemTemplate; }
			set { m_itemTemplate = value; }
		}
			

		private ITemplate m_altenateItemTemplate;
        /// <summary>
        /// Gets or sets the alternating item template.
        /// </summary>
        /// <value>The alternating item template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(TvtItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate AlternatingItemTemplate
		{
			get { return m_altenateItemTemplate; }
			set { m_altenateItemTemplate = value; }
		}

		private ITemplate m_footerTemplate;
        /// <summary>
        /// Gets or sets the footer template.
        /// </summary>
        /// <value>The footer template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(TvtItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate FooterTemplate
		{
			get { return m_footerTemplate; }
			set { m_footerTemplate = value; }
		}

        /// <summary>
        /// Gets or sets the data source ID.
        /// </summary>
        /// <value>The data source ID.</value>
		[Category("Data")]
		public virtual string DataSourceID
		{
			get
			{
				if (ViewState["DataSourceID"] == null)
				{
					return string.Empty;
				}
				return (string)ViewState["DataSourceID"];
			}
			set
			{
				ViewState["DataSourceID"] = value;
			}
		}

		//[Category("Data")]
		//public virtual string DataMember
		//{
		//    get
		//    {
		//        if (ViewState["DataMember"] == null)
		//        {
		//            return string.Empty;
		//        }
		//        return (string)ViewState["DataMember"];
		//    }
		//    set
		//    {
		//        ViewState["DataMember"] = value;
		//    }
		//}

		//private ProductDataSourceView m_currentView;

		System.Collections.IEnumerable m_currentView;
        /// <summary>
        /// Connects to data source view.
        /// </summary>
        /// <returns>an IEnumerable of DataSourceView</returns>
		private System.Collections.IEnumerable ConnectToDataSourceView()
		{
			if (m_currentView == null)
			{
				SPL.Web.Data.TvtDataSource datasource = null;
				//First look in the naming container
            Control ctl = this.NamingContainer.FindControl(DataSourceID);
            if (ctl == null)
            {
               //if not found, look at the page level
               ctl = this.Page.FindControl(DataSourceID);
               if (ctl == null)
               {
                  throw new System.Web.HttpException("Datasource does not exists");
               }
            }
				datasource = ctl as SPL.Web.Data.TvtDataSource;
				if (datasource == null)
				{
					throw new System.Web.HttpException("Datasource must be data control");
				}
				
				System.Collections.IEnumerable dsv = datasource.GetEntityList(); //this.DataMember);
				if (dsv == null)
				{
					throw new System.Web.HttpException("View not found");
				}
				m_currentView = dsv;
			}
			return m_currentView;
		}

        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
		protected override void CreateChildControls()
		{
			if (ChildControlsCreated)
			{
				return;
			}
			Controls.Clear();

			System.Collections.IEnumerable datas = (System.Collections.IEnumerable)ConnectToDataSourceView();

			if (datas != null)
			{
				if (m_headerTemplate != null)
				{
					Control headerItem = new Control();
					m_headerTemplate.InstantiateIn(headerItem);
					Controls.Add(headerItem);
				}

				int pos = 0;
				foreach (object o in datas)
				{
					SPL.Entities.Tvt entity = o as SPL.Entities.Tvt;
					TvtItem container = new TvtItem(entity);

					if (m_itemTemplate != null && (pos % 2) == 0)
					{
						m_itemTemplate.InstantiateIn(container);
					}
					else
					{
						if (m_altenateItemTemplate != null)
						{
							m_altenateItemTemplate.InstantiateIn(container);
						}
						else if (m_itemTemplate != null)
						{
							m_itemTemplate.InstantiateIn(container);
						}
						else
						{
							// no template !!!
						}
					}
					Controls.Add(container);
					pos++;
				}

				if (m_footerTemplate != null)
				{
					Control footerItem = new Control();
					m_footerTemplate.InstantiateIn(footerItem);
					Controls.Add(footerItem);
				}
				ChildControlsCreated = true;
			}
		}

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.PreRender"></see> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"></see> object that contains the event data.</param>
		protected override void OnPreRender(EventArgs e)
		{
			base.DataBind();
		}

		#region Design time
        /// <summary>
        /// Renders at design time.
        /// </summary>
        /// <returns>a  string of the Designed HTML</returns>
		internal string RenderAtDesignTime()
		{			
			return "Designer currently not implemented"; 
		}

		#endregion
	}

    /// <summary>
    /// A wrapper type for the entity
    /// </summary>
	[System.ComponentModel.ToolboxItem(false)]
	public class TvtItem : System.Web.UI.Control, System.Web.UI.INamingContainer
	{
		private SPL.Entities.Tvt _entity;

        /// <summary>
        /// Initializes a new instance of the <see cref="T:TvtItem"/> class.
        /// </summary>
		public TvtItem()
			: base()
		{ }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:TvtItem"/> class.
        /// </summary>
		public TvtItem(SPL.Entities.Tvt entity)
			: base()
		{
			_entity = entity;
		}
		
        /// <summary>
        /// Gets the Id
        /// </summary>
        /// <value>The Id.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int64 Id
		{
			get { return _entity.Id; }
		}
        /// <summary>
        /// Gets the I1InputDate
        /// </summary>
        /// <value>The I1InputDate.</value>
		[System.ComponentModel.Bindable(true)]
		public System.DateTime I1InputDate
		{
			get { return _entity.I1InputDate; }
		}
        /// <summary>
        /// Gets the I7CondBhLuongNhap
        /// </summary>
        /// <value>The I7CondBhLuongNhap.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I7CondBhLuongNhap
		{
			get { return _entity.I7CondBhLuongNhap; }
		}
        /// <summary>
        /// Gets the I8CondBhTenMeNhap
        /// </summary>
        /// <value>The I8CondBhTenMeNhap.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I8CondBhTenMeNhap
		{
			get { return _entity.I8CondBhTenMeNhap; }
		}
        /// <summary>
        /// Gets the I9CondBhKhac
        /// </summary>
        /// <value>The I9CondBhKhac.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I9CondBhKhac
		{
			get { return _entity.I9CondBhKhac; }
		}
        /// <summary>
        /// Gets the I10CondBhd1013
        /// </summary>
        /// <value>The I10CondBhd1013.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I10CondBhd1013
		{
			get { return _entity.I10CondBhd1013; }
		}
        /// <summary>
        /// Gets the I11BuproFt1011Nhap
        /// </summary>
        /// <value>The I11BuproFt1011Nhap.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I11BuproFt1011Nhap
		{
			get { return _entity.I11BuproFt1011Nhap; }
		}
        /// <summary>
        /// Gets the I12BuproFt1012Nhap
        /// </summary>
        /// <value>The I12BuproFt1012Nhap.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I12BuproFt1012Nhap
		{
			get { return _entity.I12BuproFt1012Nhap; }
		}
        /// <summary>
        /// Gets the I13BuproXeBonNhap
        /// </summary>
        /// <value>The I13BuproXeBonNhap.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I13BuproXeBonNhap
		{
			get { return _entity.I13BuproXeBonNhap; }
		}
        /// <summary>
        /// Gets the I14BuproKhac
        /// </summary>
        /// <value>The I14BuproKhac.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I14BuproKhac
		{
			get { return _entity.I14BuproKhac; }
		}
        /// <summary>
        /// Gets the I15Dlpg
        /// </summary>
        /// <value>The I15Dlpg.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I15Dlpg
		{
			get { return _entity.I15Dlpg; }
		}
        /// <summary>
        /// Gets the I16CondNcsz7900
        /// </summary>
        /// <value>The I16CondNcsz7900.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I16CondNcsz7900
		{
			get { return _entity.I16CondNcsz7900; }
		}
        /// <summary>
        /// Gets the I17CondNcsKhac
        /// </summary>
        /// <value>The I17CondNcsKhac.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I17CondNcsKhac
		{
			get { return _entity.I17CondNcsKhac; }
		}
        /// <summary>
        /// Gets the I18CondNcsBatchNo
        /// </summary>
        /// <value>The I18CondNcsBatchNo.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I18CondNcsBatchNo
		{
			get { return _entity.I18CondNcsBatchNo; }
		}
        /// <summary>
        /// Gets the I19d7900
        /// </summary>
        /// <value>The I19d7900.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I19d7900
		{
			get { return _entity.I19d7900; }
		}
        /// <summary>
        /// Gets the I20CondBhXuatTheoMeter
        /// </summary>
        /// <value>The I20CondBhXuatTheoMeter.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I20CondBhXuatTheoMeter
		{
			get { return _entity.I20CondBhXuatTheoMeter; }
		}
        /// <summary>
        /// Gets the I21CondBhXuatTheoTank
        /// </summary>
        /// <value>The I21CondBhXuatTheoTank.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I21CondBhXuatTheoTank
		{
			get { return _entity.I21CondBhXuatTheoTank; }
		}
        /// <summary>
        /// Gets the I22CondBhXuatTheoGiamDinh
        /// </summary>
        /// <value>The I22CondBhXuatTheoGiamDinh.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I22CondBhXuatTheoGiamDinh
		{
			get { return _entity.I22CondBhXuatTheoGiamDinh; }
		}
        /// <summary>
        /// Gets the I23CondBhXuatKhac
        /// </summary>
        /// <value>The I23CondBhXuatKhac.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I23CondBhXuatKhac
		{
			get { return _entity.I23CondBhXuatKhac; }
		}
        /// <summary>
        /// Gets the I24BuproTheoMeter
        /// </summary>
        /// <value>The I24BuproTheoMeter.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I24BuproTheoMeter
		{
			get { return _entity.I24BuproTheoMeter; }
		}
        /// <summary>
        /// Gets the I25BuproTheoTank
        /// </summary>
        /// <value>The I25BuproTheoTank.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I25BuproTheoTank
		{
			get { return _entity.I25BuproTheoTank; }
		}
        /// <summary>
        /// Gets the I27BuproXuatTheoGiamDinhTamTinh
        /// </summary>
        /// <value>The I27BuproXuatTheoGiamDinhTamTinh.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I27BuproXuatTheoGiamDinhTamTinh
		{
			get { return _entity.I27BuproXuatTheoGiamDinhTamTinh; }
		}
        /// <summary>
        /// Gets the I28BuproXuatKhac
        /// </summary>
        /// <value>The I28BuproXuatKhac.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I28BuproXuatKhac
		{
			get { return _entity.I28BuproXuatKhac; }
		}
        /// <summary>
        /// Gets the I29CondNcsXuatTheoMeter
        /// </summary>
        /// <value>The I29CondNcsXuatTheoMeter.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I29CondNcsXuatTheoMeter
		{
			get { return _entity.I29CondNcsXuatTheoMeter; }
		}
        /// <summary>
        /// Gets the I30CondNcsXuatTheoTank
        /// </summary>
        /// <value>The I30CondNcsXuatTheoTank.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I30CondNcsXuatTheoTank
		{
			get { return _entity.I30CondNcsXuatTheoTank; }
		}
        /// <summary>
        /// Gets the I31CondNcsXuatTheoGiamDinh
        /// </summary>
        /// <value>The I31CondNcsXuatTheoGiamDinh.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I31CondNcsXuatTheoGiamDinh
		{
			get { return _entity.I31CondNcsXuatTheoGiamDinh; }
		}
        /// <summary>
        /// Gets the I32CondNcsXuatKhac
        /// </summary>
        /// <value>The I32CondNcsXuatKhac.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I32CondNcsXuatKhac
		{
			get { return _entity.I32CondNcsXuatKhac; }
		}
        /// <summary>
        /// Gets the I33CondNcsLiftNo
        /// </summary>
        /// <value>The I33CondNcsLiftNo.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I33CondNcsLiftNo
		{
			get { return _entity.I33CondNcsLiftNo; }
		}
        /// <summary>
        /// Gets the I34LpgXaDot
        /// </summary>
        /// <value>The I34LpgXaDot.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I34LpgXaDot
		{
			get { return _entity.I34LpgXaDot; }
		}
        /// <summary>
        /// Gets the I35CondXaDot
        /// </summary>
        /// <value>The I35CondXaDot.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I35CondXaDot
		{
			get { return _entity.I35CondXaDot; }
		}
        /// <summary>
        /// Gets the I36CondBhKhoiLuongTon
        /// </summary>
        /// <value>The I36CondBhKhoiLuongTon.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I36CondBhKhoiLuongTon
		{
			get { return _entity.I36CondBhKhoiLuongTon; }
		}
        /// <summary>
        /// Gets the I37CondBhTonMuca
        /// </summary>
        /// <value>The I37CondBhTonMuca.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I37CondBhTonMuca
		{
			get { return _entity.I37CondBhTonMuca; }
		}
        /// <summary>
        /// Gets the I38CondBhTonMucb
        /// </summary>
        /// <value>The I38CondBhTonMucb.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I38CondBhTonMucb
		{
			get { return _entity.I38CondBhTonMucb; }
		}
        /// <summary>
        /// Gets the I39BuproTon
        /// </summary>
        /// <value>The I39BuproTon.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I39BuproTon
		{
			get { return _entity.I39BuproTon; }
		}
        /// <summary>
        /// Gets the I40CondNcsKhoiLuongTon
        /// </summary>
        /// <value>The I40CondNcsKhoiLuongTon.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I40CondNcsKhoiLuongTon
		{
			get { return _entity.I40CondNcsKhoiLuongTon; }
		}
        /// <summary>
        /// Gets the I41CondNcsTonMuca
        /// </summary>
        /// <value>The I41CondNcsTonMuca.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I41CondNcsTonMuca
		{
			get { return _entity.I41CondNcsTonMuca; }
		}
        /// <summary>
        /// Gets the I42CondNcsTonMucb
        /// </summary>
        /// <value>The I42CondNcsTonMucb.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I42CondNcsTonMucb
		{
			get { return _entity.I42CondNcsTonMucb; }
		}
        /// <summary>
        /// Gets the I65GhiChuNcs
        /// </summary>
        /// <value>The I65GhiChuNcs.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I65GhiChuNcs
		{
			get { return _entity.I65GhiChuNcs; }
		}
        /// <summary>
        /// Gets the I66GhiChuNhap
        /// </summary>
        /// <value>The I66GhiChuNhap.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I66GhiChuNhap
		{
			get { return _entity.I66GhiChuNhap; }
		}
        /// <summary>
        /// Gets the I67GhiChuXuat
        /// </summary>
        /// <value>The I67GhiChuXuat.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I67GhiChuXuat
		{
			get { return _entity.I67GhiChuXuat; }
		}
        /// <summary>
        /// Gets the I68GhiChuTon
        /// </summary>
        /// <value>The I68GhiChuTon.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I68GhiChuTon
		{
			get { return _entity.I68GhiChuTon; }
		}
        /// <summary>
        /// Gets the I69GhiChuKhac
        /// </summary>
        /// <value>The I69GhiChuKhac.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I69GhiChuKhac
		{
			get { return _entity.I69GhiChuKhac; }
		}
        /// <summary>
        /// Gets the Status
        /// </summary>
        /// <value>The Status.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32 Status
		{
			get { return _entity.Status; }
		}
        /// <summary>
        /// Gets the CreatedUser
        /// </summary>
        /// <value>The CreatedUser.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32 CreatedUser
		{
			get { return _entity.CreatedUser; }
		}
        /// <summary>
        /// Gets the Hid
        /// </summary>
        /// <value>The Hid.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int64? Hid
		{
			get { return _entity.Hid; }
		}
        /// <summary>
        /// Gets the CreatedDate
        /// </summary>
        /// <value>The CreatedDate.</value>
		[System.ComponentModel.Bindable(true)]
		public System.DateTime CreatedDate
		{
			get { return _entity.CreatedDate; }
		}

        /// <summary>
        /// Gets a <see cref="T:SPL.Entities.Tvt"></see> object
        /// </summary>
        /// <value></value>
        [System.ComponentModel.Bindable(true)]
        public SPL.Entities.Tvt Entity
        {
            get { return _entity; }
        }
	}
}
